<?php

use yii\db\Migration;

/**
 * Class m200423_075300_init_table
 */
class m200423_075300_init_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        \Yii::$app->db->createCommand("
        SET NAMES utf8mb4;
        SET FOREIGN_KEY_CHECKS = 0;
       
        -- ----------------------------
        -- Table structure for admin_operation_log
        -- ----------------------------
        DROP TABLE IF EXISTS `admin_operation_log`;
        CREATE TABLE `admin_operation_log` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `method` varchar(100) NOT NULL COMMENT '操作方法',
          `admin_user_id` int(11) unsigned DEFAULT NULL COMMENT '管理员',
          `content` varchar(1000) DEFAULT NULL COMMENT '行为',
          `input` text COMMENT '参数',
          `create_time` datetime NOT NULL COMMENT '记录时间',
          `update_time` datetime NOT NULL COMMENT '修改时间',
          PRIMARY KEY (`id`),
          KEY `operation_method` (`method`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='后台操作日志表';
        
        -- ----------------------------
        -- Table structure for app_patch
        -- ----------------------------
        DROP TABLE IF EXISTS `app_patch`;
        CREATE TABLE `app_patch` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `version` varchar(100) NOT NULL COMMENT '版本',
          `patch` smallint(6) NOT NULL DEFAULT '1' COMMENT '热更版本号',
          `status` tinyint(3) NOT NULL DEFAULT '1' COMMENT '0:启用,1:隐藏',
          `desc` varchar(255) DEFAULT NULL COMMENT '热更内容',
          `create_time` datetime NOT NULL,
          `update_time` datetime NOT NULL,
          `source` text COMMENT '更新的渠道范围，null为全部更新',
          PRIMARY KEY (`id`),
          KEY `patch_version_indexes` (`version`,`patch`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='版本热更记录表';
        
        -- ----------------------------
        -- Table structure for app_source
        -- ----------------------------
        DROP TABLE IF EXISTS `app_source`;
        CREATE TABLE `app_source` (
          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
          `user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '操作用户id',
          `source_id` int(11) unsigned NOT NULL COMMENT '渠道号',
          `name` char(50) NOT NULL DEFAULT '' COMMENT '渠道名称',
          `create_time` datetime NOT NULL COMMENT '启动时间',
          `update_time` datetime NOT NULL COMMENT '修改时间',
          `app_version` varchar(10) NOT NULL DEFAULT '1.0.0' COMMENT '当前版本',
          `check_status` tinyint(3) NOT NULL DEFAULT '0' COMMENT '当前审核状态',
          PRIMARY KEY (`id`),
          UNIQUE KEY `source_id` (`source_id`),
          KEY `source` (`source_id`)
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COMMENT='APP端source字段渠道映射表';
        
        -- ----------------------------
        -- Table structure for app_version
        -- ----------------------------
        DROP TABLE IF EXISTS `app_version`;
        CREATE TABLE `app_version` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `status` tinyint(3) NOT NULL COMMENT '0为启动，1为不启用',
          `url` varchar(255) DEFAULT NULL COMMENT '更新地址',
          `os` tinyint(3) NOT NULL COMMENT '操作系统,0为安卓,1为ios',
          `to_version` varchar(20) NOT NULL COMMENT '最新版本号',
          `to_version_num` smallint(6) unsigned DEFAULT NULL COMMENT '最大版本号数字',
          `type` tinyint(3) NOT NULL COMMENT '0为强制更新,1为非强制更新',
          `content` varchar(500) DEFAULT NULL COMMENT '更新内容',
          `create_time` datetime NOT NULL COMMENT '创建时间',
          `update_time` datetime NOT NULL COMMENT '更新时间',
          `version` varchar(120) NOT NULL COMMENT '需要更新的版本号',
          `source` text COMMENT '更新的渠道范围，null为全部更新',
          `install_type` tinyint(3) NOT NULL DEFAULT '0' COMMENT '0为google play,1为apk更新',
          `operator` tinyint(3) NOT NULL DEFAULT '1' COMMENT '1为=，2为<',
          `is_last` tinyint(3) NOT NULL DEFAULT '1' COMMENT '2为最新版本，1为普通版本',
          PRIMARY KEY (`id`),
          KEY `app-version-indexes` (`version`,`to_version`,`os`,`operator`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='版本更新表';
        
        -- ----------------------------
        -- Table structure for app_ad
        -- ----------------------------
        DROP TABLE IF EXISTS `app_ad`;
        CREATE TABLE `app_ad` (
          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
          `title` varchar(100) NOT NULL COMMENT '广告名称',
          `image` varchar(255) NOT NULL COMMENT '图片地址',
          `open_type` tinyint(3) NOT NULL DEFAULT '1' COMMENT '跳转类型，1为无跳转，2为内连接，3外连接',
          `jump_url` varchar(255) NOT NULL DEFAULT '' COMMENT '跳转地址',
          `position` tinyint(3) NOT NULL DEFAULT '1' COMMENT '1为首页广告',
          `status` tinyint(3) NOT NULL DEFAULT '1' COMMENT '1为上架，2为下架',
          `weight` int(11) NOT NULL DEFAULT '1' COMMENT '权重',
          `create_time` datetime NOT NULL,
          `update_time` datetime NOT NULL,
          `is_del` tinyint(3) NOT NULL DEFAULT '1' COMMENT '1为显示，2为删除',
          PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='广告表';
        
        -- ----------------------------
        -- Table structure for app_ad_click
        -- ----------------------------
        DROP TABLE IF EXISTS `app_ad_click`;
        CREATE TABLE `app_ad_click` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `uuid` varchar(60) DEFAULT NULL COMMENT '用户唯一设备ID',
          `ad_id` int(11) unsigned NOT NULL COMMENT '广告ID',
          `num` int(11) unsigned NOT NULL DEFAULT '1' COMMENT '点击次数',
          `create_time` datetime NOT NULL COMMENT '今日首次点击时间',
          `update_time` datetime NOT NULL COMMENT '今日最后一次点击时间',
          PRIMARY KEY (`id`),
          KEY `ad-click-uuid-indexes` (`uuid`,`ad_id`,`create_time`),
          KEY `ad-click-ad-indexes` (`ad_id`,`create_time`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='广告点击记录表';

        -- ----------------------------
        -- Table structure for banner
        -- ----------------------------
        DROP TABLE IF EXISTS `banner`;
        CREATE TABLE `banner` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `title` varchar(255) DEFAULT NULL,
          `image` varchar(255) NOT NULL COMMENT 'banner地址',
          `open_type` tinyint(3) NOT NULL DEFAULT '0' COMMENT '0:url跳转',
          `jump_url` varchar(255) DEFAULT NULL COMMENT '跳转地址',
          `create_time` datetime NOT NULL,
          `update_time` datetime NOT NULL,
          `status` tinyint(3) NOT NULL DEFAULT '0' COMMENT '0:发布，1:下架',
          `order` int(11) NOT NULL DEFAULT '0' COMMENT '排序：越大越在前',
          `position` tinyint(3) NOT NULL DEFAULT '0' COMMENT 'banner位置',
          `start_time` datetime DEFAULT NULL COMMENT '开始时间',
          `end_time` datetime DEFAULT NULL COMMENT '截止时间',
          PRIMARY KEY (`id`),
          KEY `banner_time_indexes` (`start_time`,`end_time`)
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COMMENT='banner表';
        
        -- ----------------------------
        -- Table structure for login_logs
        -- ----------------------------
        DROP TABLE IF EXISTS `login_logs`;
        CREATE TABLE `login_logs` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `user_id` int(11) unsigned NOT NULL COMMENT '用户ID',
          `source` smallint(6) unsigned NOT NULL COMMENT '来源',
          `device` varchar(100) DEFAULT NULL COMMENT '极光设备号',
          `version` varchar(100) NOT NULL COMMENT '版本号',
          `os` tinyint(3) NOT NULL DEFAULT '0' COMMENT '操作系统，0为安卓,1为ios',
          `ip` varchar(100) DEFAULT NULL COMMENT '登陆IP',
          `mobile_model` varchar(255) DEFAULT NULL COMMENT '手机型号',
          `create_time` datetime NOT NULL COMMENT '登陆时间',
          `uuid` varchar(100) DEFAULT NULL COMMENT '硬件唯一标识符',
          PRIMARY KEY (`id`),
          KEY `login_logs_user_indexes` (`user_id`,`mobile_model`(191)),
          KEY `login_logs_time_indexes` (`create_time`),
          KEY `login-log-uuid-indexes` (`uuid`),
          KEY `login-device-index` (`device`)
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COMMENT='登录日志表';
        
        -- ----------------------------
        -- Table structure for push_message
        -- ----------------------------
        DROP TABLE IF EXISTS `push_message`;
        CREATE TABLE `push_message` (
          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
          `title` varchar(500) NOT NULL COMMENT '推送标题',
          `content` varchar(1200) NOT NULL COMMENT '推送内容',
          `user_ids` text COMMENT '发送的对象,当为全部时为all_user',
          `open_type` int(11) NOT NULL DEFAULT '1' COMMENT '1为打开APP',
          `open_type_args` varchar(500) DEFAULT NULL COMMENT '传递的参数',
          `img_url` varchar(255) DEFAULT NULL COMMENT '传递的图片',
          `status` tinyint(3) NOT NULL DEFAULT '0' COMMENT '0为待确定',
          `send_time` datetime DEFAULT NULL COMMENT '推送时间',
          `push_method` tinyint(3) NOT NULL DEFAULT '0' COMMENT '0为程序推送，1为后台手动推送',
          `create_time` datetime NOT NULL COMMENT '创建时间',
          `update_time` datetime NOT NULL COMMENT '修改时间',
          PRIMARY KEY (`id`),
          KEY `push_message_status_indexes` (`status`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='推送记录表';
        
        -- ----------------------------
        -- Table structure for push_message_log
        -- ----------------------------
        DROP TABLE IF EXISTS `push_message_log`;
        CREATE TABLE `push_message_log` (
          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
          `push_message_id` int(11) unsigned NOT NULL COMMENT '推送ID',
          `users` text COMMENT '推送对象,device',
          `response` text COMMENT '推送结果',
          `create_time` datetime NOT NULL COMMENT '生成时间',
          `source` int(11) NOT NULL DEFAULT '0' COMMENT '推送渠道',
          PRIMARY KEY (`id`),
          KEY `push_message_push_id_indexes` (`push_message_id`)
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COMMENT='推送记录日志表';
        
        -- ----------------------------
        -- Table structure for notice
        -- ----------------------------
        DROP TABLE IF EXISTS `notice`;
        CREATE TABLE `notice` (
          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
          `title` varchar(255) NOT NULL COMMENT '通知标题',
          `content` varchar(500) NOT NULL,
          `open_type` tinyint(3) NOT NULL DEFAULT '0' COMMENT '0:普通通知（无跳转）,1:跳转h5',
          `type` tinyint(3) NOT NULL DEFAULT '0' COMMENT '0为全站推送,1为指定推送',
          `jump_url` varchar(255) DEFAULT NULL COMMENT '跳转地址',
          `create_time` datetime NOT NULL,
          `update_time` datetime NOT NULL,
          `is_push` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否推送激光,true,推送',
          `open_type_args` varchar(500) DEFAULT NULL COMMENT '打开参数',
          `user_id` int(11) unsigned DEFAULT '0' COMMENT '通知对象',
          PRIMARY KEY (`id`),
          KEY `notice_user_indexes` (`user_id`,`type`),
          KEY `notice_create_time_indexes` (`create_time`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统通知表';

        -- ----------------------------
        -- Table structure for sms
        -- ----------------------------
        DROP TABLE IF EXISTS `sms`;
        CREATE TABLE `sms` (
          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
          `mobile` char(11) NOT NULL COMMENT '用户手机号',
          `code` char(6) NOT NULL COMMENT '验证码',
          `type` tinyint(3) unsigned DEFAULT NULL COMMENT '发送类型',
          `version` char(20) DEFAULT '' COMMENT '版本号',
          `content` varchar(255) NOT NULL COMMENT '文本内容',
          `create_time` datetime NOT NULL COMMENT '创建时间',
          `update_time` datetime NOT NULL COMMENT '更新时间',
          PRIMARY KEY (`id`)
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COMMENT='短信验证码详情表';
        
        -- ----------------------------
        -- Table structure for stats_active_user
        -- ----------------------------
        DROP TABLE IF EXISTS `stats_active_user`;
        CREATE TABLE `stats_active_user` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `user_id` int(11) unsigned NOT NULL COMMENT '用户ID',
          `uuid` varchar(100) NOT NULL COMMENT '设备号',
          `active_time` datetime DEFAULT NULL COMMENT '活跃时间',
          PRIMARY KEY (`id`),
          KEY `app_active_indexes` (`user_id`,`uuid`,`active_time`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户日活表';
        
        -- ----------------------------
        -- Table structure for stats_app_user
        -- ----------------------------
        DROP TABLE IF EXISTS `stats_app_user`;
        CREATE TABLE `stats_app_user` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `equipment_num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '当日设备数量',
          `register_num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '当日注册数量',
          `register_percent` float NOT NULL DEFAULT '0' COMMENT '当日注册率',
          `login_num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '当日唤醒APP的登陆用户数量',
          `day_created_user_num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '日活跃，当日创作用户数量',
          `day_created_num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '当日创作次数',
          `keep_info` text COMMENT '留存率，次日，7日，总留存',
          `today` datetime NOT NULL COMMENT '报表时间',
          `create_time` datetime NOT NULL COMMENT '创建时间',
          `update_time` datetime NOT NULL COMMENT '编辑时间',
          PRIMARY KEY (`id`),
          KEY `stats-user-date` (`today`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='统计表';
        
        -- ----------------------------
        -- Table structure for stats_start_log
        -- ----------------------------
        DROP TABLE IF EXISTS `stats_start_log`;
        CREATE TABLE `stats_start_log` (
          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
          `uuid` varchar(100) NOT NULL COMMENT '唯一标识符',
          `num` int(11) unsigned DEFAULT NULL COMMENT '今日启动次数',
          `create_time` datetime NOT NULL COMMENT '启动时间',
          `update_time` datetime NOT NULL COMMENT '修改时间',
          `source` smallint(6) unsigned DEFAULT NULL COMMENT '启动来源',
          PRIMARY KEY (`id`),
          KEY `stats-start-num-indexes` (`num`),
          KEY `stats-start-uuid-indexes` (`uuid`,`create_time`,`source`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='打点启动日志表';
        
        -- ----------------------------
        -- Table structure for sys_conf
        -- ----------------------------
        DROP TABLE IF EXISTS `sys_conf`;
        CREATE TABLE `sys_conf` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `key` varchar(100) NOT NULL COMMENT 'key',
          `val` text NOT NULL COMMENT 'val',
          `status` tinyint(3) NOT NULL DEFAULT '1' COMMENT '状态0 关闭 1启用',
          PRIMARY KEY (`id`),
          UNIQUE KEY `key` (`key`),
          KEY `k` (`key`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统配置';
        
        -- ----------------------------
        -- Table structure for user_active
        -- ----------------------------
        DROP TABLE IF EXISTS `user_active`;
        CREATE TABLE `user_active` (
          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
          `user_id` int(11) unsigned NOT NULL COMMENT '用户id',
          `last_active` datetime NOT NULL COMMENT '活跃时间',
          `version` char(35) NOT NULL COMMENT '用户版本号',
          `source` smallint(6) DEFAULT '0' COMMENT '渠道来源',
          PRIMARY KEY (`id`),
          UNIQUE KEY `uni_user_active` (`user_id`),
          KEY `user_active_ud_inx` (`user_id`,`last_active`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户活跃时间记录表';
        
        -- ----------------------------
        -- Table structure for user_black_list
        -- ----------------------------
        DROP TABLE IF EXISTS `user_black_list`;
        CREATE TABLE `user_black_list` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `user_id` int(11) unsigned NOT NULL COMMENT '用户ID',
          `black_user_id` int(11) unsigned NOT NULL COMMENT '被加入黑名单用户',
          `create_time` datetime NOT NULL COMMENT '拉黑时间',
          PRIMARY KEY (`id`),
          UNIQUE KEY `black-list-user` (`user_id`,`black_user_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户黑名单表';
        
        -- ----------------------------
        -- Table structure for user_feedback
        -- ----------------------------
        DROP TABLE IF EXISTS `user_feedback`;
        CREATE TABLE `user_feedback` (
          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
          `user_id` int(11) unsigned NOT NULL COMMENT '用户id',
          `content` varchar(255) NOT NULL COMMENT '反馈内容',
          `create_time` datetime NOT NULL,
          `update_time` datetime NOT NULL,
          `reply_id` int(11) NOT NULL DEFAULT '0' COMMENT '回复id',
          PRIMARY KEY (`id`),
          KEY `user_feedback_user_id_inx` (`user_id`,`create_time`),
          KEY `reply_id` (`reply_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户反馈';
        
        -- ----------------------------
        -- Table structure for user_feedback_reply
        -- ----------------------------
        DROP TABLE IF EXISTS `user_feedback_reply`;
        CREATE TABLE `user_feedback_reply` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `fed_id` int(11) DEFAULT '0' COMMENT '反馈id',
          `customer_id` int(11) DEFAULT '0' COMMENT '客服id',
          `content` varchar(255) NOT NULL DEFAULT '' COMMENT '回复内容',
          `create_time` datetime DEFAULT NULL,
          `update_time` datetime DEFAULT NULL,
          PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='意见反馈回复';
        
        -- ----------------------------
        -- Table structure for user_unusual_detail
        -- ----------------------------
        DROP TABLE IF EXISTS `user_unusual_detail`;
        CREATE TABLE `user_unusual_detail` (
          `id` bigint(20) NOT NULL AUTO_INCREMENT,
          `user_id` bigint(20) NOT NULL COMMENT '用户id',
          `emulator` tinyint(3) NOT NULL DEFAULT '0' COMMENT '模拟器',
          `virtual` tinyint(3) NOT NULL DEFAULT '0' COMMENT '多开',
          `time` datetime NOT NULL COMMENT '上报时间',
          PRIMARY KEY (`id`),
          KEY `user_id` (`user_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户异常上报日志';
        
        -- ----------------------------
        -- Table structure for user_unusual_info
        -- ----------------------------
        DROP TABLE IF EXISTS `user_unusual_info`;
        CREATE TABLE `user_unusual_info` (
          `id` bigint(20) NOT NULL AUTO_INCREMENT,
          `user_id` bigint(20) NOT NULL COMMENT '用户id',
          `emulator_num` int(11) NOT NULL DEFAULT '0' COMMENT '模拟器',
          `virtual_num` int(11) NOT NULL DEFAULT '0' COMMENT '多开',
          `other_num` int(11) NOT NULL DEFAULT '0' COMMENT '其他原因',
          `create_time` datetime NOT NULL COMMENT '上报时间',
          `update_time` datetime NOT NULL COMMENT '更新时间',
          PRIMARY KEY (`id`),
          KEY `user_id` (`user_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户异常上报统计';
        
        -- ----------------------------
        -- Table structure for sensitive_words
        -- ----------------------------
        DROP TABLE IF EXISTS `sensitive_words`;
        CREATE TABLE `sensitive_words` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `word` varchar(80) COLLATE utf8mb4_bin DEFAULT NULL,
          `create_time` datetime DEFAULT NULL,
          PRIMARY KEY (`id`) USING BTREE,
          KEY `words_indexes` (`word`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='敏感词库';
        ")->execute();
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        echo "m200423_075300_init_table cannot be reverted.\n";

        return false;
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m200423_075300_init_table cannot be reverted.\n";

        return false;
    }
    */
}
